//
//  SADepartmentCollectionTableViewCell.m
//  SunOn
//
//  Created by mc on 2017/5/3.
//  Copyright © 2017年 NeoZhang. All rights reserved.
//  部门人员首页信息显示 无图片  无评论  111  图片 + 150 * height_scrle 评论 44    图片+评论  150 * height_scrle + 11 + 44

#import "SADepartmentCollectionTableViewCell.h"

@interface SADepartmentCollectionTableViewCell ()
//部门人员照片
@property (weak, nonatomic) IBOutlet UIImageView *userImage;
//部门人员名称
@property (weak, nonatomic) IBOutlet UILabel *userName;
//时间
@property (weak, nonatomic) IBOutlet UILabel *currentTime;
//所属模块  例:同业信息
@property (weak, nonatomic) IBOutlet UILabel *moduleTitle;
//内容
@property (weak, nonatomic) IBOutlet UILabel *messageContent;
//内容图片
@property (weak, nonatomic) IBOutlet UIImageView *messageImage;
//评论
@property (weak, nonatomic) IBOutlet UILabel *commentLB;
//评论背景
@property (weak, nonatomic) IBOutlet UIImageView *comentBGImage;

//layout
//消息回复高度 38
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *xiaoxiHeightLayout;

//信息背景高度 44
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *xiaoxiBGHeightLayout;

//图片高度 146
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageHeightLayout;

@end

@implementation SADepartmentCollectionTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    SAViewBorderRadius(self.huifuButton, 5, 1, [UIColor colorWithHexString:@"#f8f8f8"]);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
//控制有无照片和评论高度
- (void)configureCellsImageHeight:(NSInteger)imgHeight CommentHeight:(NSInteger)commentHeight {
    self.xiaoxiHeightLayout.constant = commentHeight;
    if (commentHeight == 0) {
        self.xiaoxiBGHeightLayout.constant = 0;
    }else {
        self.xiaoxiBGHeightLayout.constant = commentHeight + 6;
        UIImage *image = SAImageNamed(@"message_kuang");
        image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, image.size.height - 40, 0)];
        [self.comentBGImage setImage:image];
    }
    self.imageHeightLayout.constant = imgHeight;
}
//写评论
- (void)writeCommentWithStr:(NSString *)comment {
    //@"任盈盈: 哈哈哈哈哈 \n 任盈盈: 呵呵呵"
    NSArray *strArr = [comment componentsSeparatedByString:@"\n"];
    NSMutableAttributedString *allattr = [[NSMutableAttributedString alloc] init];
    for (int i = 0; i < strArr.count; i++) {
        NSArray *commentarr = [strArr[i] componentsSeparatedByString:@":"];
        NSString *peoplename = commentarr[0];
        NSString *commentStr = commentarr[1];
        NSMutableAttributedString *mAttStri = [[NSMutableAttributedString alloc] initWithString:peoplename];
        NSRange range = NSMakeRange(0, peoplename.length);
        [mAttStri addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range];
        
        NSMutableAttributedString *mAttStri2 = [[NSMutableAttributedString alloc] initWithString:commentStr];
        NSMutableAttributedString *maohao = [[NSMutableAttributedString alloc] initWithString:@":"];
        NSMutableAttributedString *huanhang = [[NSMutableAttributedString alloc] initWithString:@"\n"];
        
        [allattr appendAttributedString:mAttStri];
        [allattr appendAttributedString:maohao];
        [allattr appendAttributedString:mAttStri2];

        if (i != strArr.count - 1) {
            [allattr appendAttributedString:huanhang];
        }
    }
    self.commentLB.attributedText = allattr;
}
@end
